package com.exchange.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.exchange.entity.pojo.StarsAddress;
import com.exchange.entity.pojo.User;
import com.exchange.entity.vo.StarsAddressVo;
import com.exchange.entity.vo.StarsVo;
import com.exchange.mapper.StarsAddressMapper;
import com.exchange.mapper.StarsVoMapper;
import com.exchange.service.StarsAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【stars_address】的数据库操作Service实现
 * @createDate 2024-04-25 20:02:10
 */
@Service
public class StarsAddressServiceImpl extends ServiceImpl<StarsAddressMapper, StarsAddress>
        implements StarsAddressService {

    @Autowired
    private StarsVoMapper starsVoMapper;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public List<StarsVo> mystars(String token) {
        String s = redisTemplate.opsForValue().get("user:login" + token);
        User user = JSON.parseObject(s, User.class);
        return starsVoMapper.mystars(user.getId());
    }

    @Override
    public List<StarsAddressVo> getAllAddressByUid(Long id) {
        List<StarsAddressVo> starsAddressVoList = this.starsVoMapper.selectAddressByUid(id);
        if (ObjectUtil.isEmpty(starsAddressVoList)) {
            return null;
        }
        return starsAddressVoList;
    }

    @Override
    public StarsAddressVo getStarsAddress(String address) {
        return this.starsVoMapper.getStarsAddress(address);
    }


}




